<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>后台管理系统</title>
        <meta name="author" content="BaiYY"/>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
        <meta name="renderer" content="webkit">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap-datetimepicker.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/pages.css"/>
        <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/pages.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap-datetimepicker.min.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
    </head>
<body>
    <div class="right-sidebar" style="max-width: 1200px;">
        <ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
            <li role="presentation"><a href="logExpend.html">日志消耗</a></li>
            <li role="presentation" class="active" id="expends"><a href="expendTotal.html">{:L(GAME_EXPEND_TOTAL)}</a></li>
        </ul>

        <p>
            <h3>说明：</h3>
            <p>可手动输入查询的时间段，默认是一周的数据</p>
        </p>

        <div class="input-group">
            <span class="input-group-addon">开始时间</span>
            <input type="text" class="form-control" id="start_time" name="start_time" data-date-format="yyyy-mm-dd hh:ii:ss">
        </div>
        <div class="input-group">
            <span class="input-group-addon" >结束时间</span>
            <input type="text" class="form-control" id="end_time" name="end_time" data-date-format="yyyy-mm-dd hh:ii:ss">
        </div>
        <div class="text-center" style="margin-top: 20px"> <button class="btn btn-primary" id="cbtn">&emsp;查询&emsp;</button></div>

        <p class="bg bg-info" id="totals" style="padding: 10px;margin-top: 10px;">总消耗：<strong></strong></p>
        <section class="table-responsive">
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>消耗原因</th>
                        <th>消耗总量</th>
                    </tr>
                </thead>
                <tbody id="dataList1"></tbody>
            </table>
        </section>

        <section class="table-responsive">
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>游戏UID</th>
                        <th>累计消耗数</th>
                    </tr>
                </thead>
                <tbody id="dataList"></tbody>
            </table>
        </section>
        <div style="margin: 10px auto;" id="exports" ><a onclick="handel(this)" class="btn btn-primary">数据导出excel</a></div>
        <ul class="page" id="page" style="width: 100%;overflow: hidden;"></ul>
    </div>
    <script type="text/javascript">
        $(function () {
            $("#end_time").val(getLocalTime(new Date()/1000));
            $("#start_time").val(getLocalTime((new Date()/1000 - 604800)));
            $( "#start_time" ).datetimepicker({
                language: 'zh-CN',
                autoclose: 1,
                todayHighlight: 1,
                weekStart: 1,
                startDate: 0
            });
            $( "#end_time" ).datetimepicker({
                language: 'zh-CN',
                autoclose: 1,
                todayHighlight: 1,
                weekStart: 1,
                startDate: 0
            });
            var expends = $.trim($("#expends").text());
            if(expends == 'GAME_EXPEND_TOTAL' || expends == '') {
                $("#expends").hide();
            }

            var start_time = new Date($("#start_time").val());
            start_time = Date.parse(start_time);
            var end_time = new Date($("#end_time").val());
            end_time = Date.parse(end_time);

            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/getsExpendTotal')}",
                dataType:"json",
                data:{"start_time":start_time,"end_time":end_time},
                success: function (data) {
//                        console.log(data);
                    if(data == 'error') {
                        $("#dataList1").html("暂时没有查询到数据！");
                    }else{
                        var str = '';
                        var res = '';
                        for(var i=0 ;i<data.length;++i) {
                            switch (data[i].r) {
                                case 'pay':
                                    res = '{:L(GAME_PAY)}';
                                    break;
                                case 'payTo':
                                    res = '{:L(GAME_PAYTO)}';
                                    break;
                                case 'gmAdd':
                                    res = '{:L(GAME_ADD)}';
                                    break;
                                case 'gmAlter':
                                    res = '{:L(GAME_ALTER)}';
                                    break;
                                case 'exchangeCoin':
                                    res = '{:L(GAME_EXCHANGE)}';
                                    break;
                                case 'roomFinished':
                                    res = '{:L(GAME_ROOM)}';
                                    break;
                                case 'SevenDayReward':
                                    res = '{:L(GAME_REWARD)}';
                                    break;
                                case 'initResource':
                                    res = '{:L(GAME_INIT)}';
                                    break;
                                case 'shareReward':
                                    res = '{:L(GAME_SHARE)}';
                                    break;
                                case 'XYBBKGameCost':
                                    res = '{L(GAME_LUCK)}';
                                    break;
                                default:
                                    res = data[i].r
                            }
                            if(data[i].card < 0) {
                                str += "<tr><td>"+res+"</td><td class='card_totals'>"+data[i].card+"</td></tr>";
                            }
                        }
                        $("#dataList1").html(str);
                        var totall = $("#dataList1 td.card_totals").text();
                        totall = totall.split("-");
                        var stotals = 0;
                        for (var i=0;i<totall.length;++i) {
                            stotals += totall[i]/1;
                        }
                        $("#totals strong").text(stotals);
                    }
                }
            });


            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/everyExpend')}",
                dataType:"json",
                data:{"start_time":start_time,"end_time":end_time},
                success:function (data) {
                    if(data == 'error') {
                        $("#dataList").html("暂时没有数据");
                    }else{
                        options={
                            "id":"page",//显示页码的元素
                            "data":data,//显示数据
                            "maxshowpageitem":2,//最多显示的页码个数
                            "pagelistcount":10,//每页显示数据个数
                            "callBack":function(data) {
//							    	console.log(data);
                                var str = '';
                                for(var i=0;i<data.length;++i) {

                                    str += "<tr><td>"+data[i].uid+"</td><td>"+data[i].card+"</td></tr>"
                                }
                                $("#dataList").html(str);
                              }
                            }
                             page.init(data.length,1,options);
                        }
                    }
            });
        });


        $("#cbtn").on("click",function () {
            var start_time = new Date($("#start_time").val());
            start_time = Date.parse(start_time);
            var end_time = new Date($("#end_time").val());
            end_time = Date.parse(end_time);
            if($.trim($("#start_time").val()) == '' || $.trim($("#end_time").val()) == ''){
                alert("时间不能为空！");
                window.location.href="{:U('Admin/Main/agentOnLinePay')}";
                return false;
            }
            if(start_time > end_time || start_time == end_time) {
                alert("请注意时间的先后顺序！");
                window.location.href="{:U('Admin/Main/agentOnLinePay')}";
                return false;
            }

            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/getsExpendTotal')}",
                dataType:"json",
                data:{"start_time":start_time,"end_time":end_time},
                success: function (data) {
//                        console.log(data);
                   if(data == 'error') {
                       $("#dataList1").html("暂时没有查询到数据！");
                   }else{
                       var str = '';
                       var res = '';
                       for(var i=0 ;i<data.length;++i) {
                           switch (data[i].r) {
                               case 'pay':
                                   res = '{:L(GAME_PAY)}';
                                   break;
                               case 'payTo':
                                   res = '{:L(GAME_PAYTO)}';
                                   break;
                               case 'gmAdd':
                                   res = '{:L(GAME_ADD)}';
                                   break;
                               case 'gmAlter':
                                   res = '{:L(GAME_ALTER)}';
                                   break;
                               case 'exchangeCoin':
                                   res = '{:L(GAME_EXCHANGE)}';
                                   break;
                               case 'roomFinished':
                                   res = '{:L(GAME_ROOM)}';
                                   break;
                               case 'SevenDayReward':
                                   res = '{:L(GAME_REWARD)}';
                                   break;
                               case 'initResource':
                                   res = '{:L(GAME_INIT)}';
                                   break;
                               case 'shareReward':
                                   res = '{:L(GAME_SHARE)}';
                                   break;
                               case 'XYBBKGameCost':
                                   res = '{L(GAME_LUCK)}';
                                   break;
                               default:
                                   res = data[i].r
                           }
                            if(data[i].card < 0) {
                                str += "<tr><td>"+res+"</td><td class='card_totals'>"+data[i].card+"</td></tr>";
                            }
                       }
                       $("#dataList1").html(str);
                       var totall = $("#dataList1 td.card_totals").text();
                       totall = totall.split("-");
                       var stotals = 0;
                       for (var i=0;i<totall.length;++i) {
                           stotals += totall[i]/1;
                       }
                       $("#totals strong").text(stotals);
                   }
                }
            });

            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/everyExpend')}",
                dataType:"json",
                data:{"start_time":start_time,"end_time":end_time},
                success:function (data) {
                    if(data == 'error') {
                        $("#dataList").html("暂时没有数据");
                    }else{
                        options={
                            "id":"page",//显示页码的元素
                            "data":data,//显示数据
                            "maxshowpageitem":2,//最多显示的页码个数
                            "pagelistcount":10,//每页显示数据个数
                            "callBack":function(data) {
//							    	console.log(data);
                                var str = '';
                                for(var i=0;i<data.length;++i) {
                                    str += "<tr><td>"+data[i].uid+"</td><td>"+data[i].card+"</td></tr>"
                                }
                                $("#dataList").html(str);
                            }
                        }
                        page.init(data.length,1,options);
                    }
                }
            })
        });
        
        function handel(This) {
            var start_time = new Date($("#start_time").val());
            start_time = Date.parse(start_time);
            var end_time = new Date($("#end_time").val());
            end_time = Date.parse(end_time);

            if(start_time == '' || end_time == '') {
                alert("导出数据的时间不能为空!");
                window.location.href="{:U('Admin/Main/expendTotal')}";
                return false;
            }
            $(This).attr('href',"{:U('Admin/Main/expendExport')}?start_time="+start_time+"&end_time=" + end_time);
        }
    </script>
</body>
</html>